home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / misc / xmgr_docs.lha / xmgr_docs / aux / cnvparm.c next >
Encoding:
C/C++ Source or Header  |  1993-05-02  |  12.7 KB  |  543 lines

  1. /* $Id$
  2.  *
  3.  * Convert 1.0x parameter files to 2.xx
  4.  * Doesn't do everything, but should help.
  5.  *
  6.  */
  7. #include <stdio.h>
  8.  
  9. void main(argc, argv)
  10.     int argc;
  11.     char **argv;
  12. {
  13.     int d = 0;
  14.     if (argc < 2) {
  15.     fprintf(stderr, "Usage: %s [-d] [version 1.0x parameter file]\n", argv[0]);
  16.     fprintf(stderr, "Where -d indicates that the file is a data file with imbedded parameter settings\n");
  17.     exit(1);
  18.     }
  19.     if (!strcmp(argv[1], "-d")) {
  20.     d++;
  21.     argv++;
  22.     }
  23.     getparms(argv[1], d);
  24.     exit(0);
  25. }
  26.  
  27. void errwin(s)
  28.     char *s;
  29. {
  30.     fprintf(stderr, "%s\n", s);
  31. }
  32.  
  33. #define    BOX0    1
  34. #define    BOXCOL  52
  35. #define    BOXLIN  53
  36. #define    BOXTYPE 2
  37. #define    BOXWID  57
  38. #define    DEFCHAR 48
  39. #define    DEFCOLOR 3
  40. #define    DEFFONT 4
  41. #define    DEFLINE 5
  42. #define    DEFNTICS 55
  43. #define    DEFSYMSIZE 54
  44. #define    ERRBAR    6
  45. #define    ERRBARPER 7
  46. #define    ERRBARTYPE 8
  47. #define    GRAPHHID  9
  48. #define    GRAPHLAB  10
  49. #define    GRAPHNO  11
  50. #define    GRAPHTYPE  12
  51. #define    LABDEF  47
  52. #define    LEGSTR  13
  53. #define    LEGFLAG 14
  54. #define    LEGGAP  15
  55. #define    LEGLEN  16
  56. #define    LEGLOC  17
  57. #define    LINES   18
  58. #define    NBOXES  19
  59. #define    NLINES  20
  60. #define    NSETS   21
  61. #define    NSTRINGS 22
  62. #define    SETPROPS 23
  63. #define    STRING0   24
  64. #define STRINGDEF 25
  65. #define    SUBTITLE 26
  66. #define    TICS     27
  67. #define    TICSABS  28
  68. #define    TICSFLAG 29
  69. #define    TICSGRID 30
  70. #define    TICSINOUT  31
  71. #define    TICSINT    32
  72. #define    TICSLFLAG  33
  73. #define    TICSLOG    34
  74. #define    TICSLTOP   35
  75. #define    TICSLTYPE  36
  76. #define    TICSOP   37
  77. #define    TICSPREC   38
  78. #define    TICSSIZE   56
  79. #define    TITLE      39
  80. #define    VIEW       40
  81. #define    WORLD      41
  82. #define    XLABEL     42
  83. #define    XTICANG     43
  84. #define    XTICSKIP     50
  85. #define    YLABEL     44
  86. #define    YTICANG     49
  87. #define    YTICSKIP     51
  88. #define    ZEROAXIS   45
  89. #define    ZEROTICS   46
  90.  
  91. #define MAXPAR 57
  92.  
  93. static char cstr[] = "##grtool parameter file";    /* the standard version */
  94.  
  95. struct funcs {
  96.     char *s;
  97.     int type;
  98. };
  99.  
  100. int findf(key, s, tlen)
  101.     struct funcs key[];
  102. char *s;
  103. int tlen;
  104.  
  105. {
  106.     int low, high, mid;
  107.  
  108.     low = 0;
  109.     high = tlen - 1;
  110.     while (low <= high) {
  111.     mid = (low + high) / 2;
  112.     if (strcmp(s, key[mid].s) < 0) {
  113.         high = mid - 1;
  114.     } else {
  115.         if (strcmp(s, key[mid].s) > 0) {
  116.         low = mid + 1;
  117.         } else {
  118.         return (mid);
  119.         }
  120.     }
  121.     }
  122.     return (-1);
  123. }
  124.  
  125. char readbuf[512];
  126. int nleg, nstr;
  127. int curset = 0;            /* for legends */
  128.  
  129. getparms(plfile, d)
  130.     char plfile[];
  131.  
  132. {
  133.     int icheck, ptype;
  134.     char s[256];
  135.     FILE *pp;
  136.  
  137.     if ((pp = fopen(plfile, "r")) == NULL) {
  138.     sprintf(readbuf, "Can't open parameter file %s", plfile);
  139.     errwin(readbuf);
  140.     plfile[0] = 0;
  141.     } else {
  142.     fgets(s, 255, pp);
  143.     s[strlen(s) - 1] = 0;
  144.     icheck = strcmp(s, cstr);
  145.     if (icheck) {
  146.         sprintf(readbuf, "File %s not legal parameter file", plfile);
  147.         errwin(readbuf);
  148.         fclose(pp);
  149.         return;
  150.     }
  151.     while (fgets(readbuf, 511, pp) != NULL) {
  152.         if (d) {
  153.         if (readbuf[0] = '@') {
  154.             ptype = read_param(readbuf);
  155.         } else {
  156.             puts(readbuf);
  157.         }
  158.         } else {
  159.         ptype = read_param(readbuf);
  160.         }
  161.     }
  162.     fclose(pp);
  163.     }
  164. }
  165.  
  166. struct funcs parmnames[] = {
  167.                 "box", BOX0,
  168.                 "boxcolor", BOXCOL,
  169.                 "boxlinestyle", BOXLIN,
  170.                 "boxlinewidth", BOXWID,
  171.                 "boxtypes", BOXTYPE,
  172.                 "defchar", DEFCHAR,
  173.                 "defcolor", DEFCOLOR,
  174.                 "deffont", DEFFONT,
  175.                 "defline", DEFLINE,
  176.                 "defntics", DEFNTICS,
  177.                 "defsymsize", DEFSYMSIZE,
  178.                 "errorbar", ERRBAR,
  179.                 "errorbarper", ERRBARPER,
  180.                 "errorbartype", ERRBARTYPE,
  181.                 "graphhid", GRAPHHID,
  182.                 "graphlab", GRAPHLAB,
  183.                 "graphno", GRAPHNO,
  184.                 "graphtype", GRAPHTYPE,
  185.                 "labdef", LABDEF,
  186.                 "legendflag", LEGFLAG,
  187.                 "legendstr", LEGSTR,
  188.                 "leggap", LEGGAP,
  189.                 "leglen", LEGLEN,
  190.                 "legloc", LEGLOC,
  191.                 "line", LINES,
  192.                 "nboxes", NBOXES,
  193.                 "nlines", NLINES,
  194.                 "nsets", NSETS,
  195.                 "nstrings", NSTRINGS,
  196.                 "setprops", SETPROPS,
  197.                 "string", STRING0,
  198.                 "stringdef", STRINGDEF,
  199.                 "subtitle", SUBTITLE,
  200.                 "ticflags", TICSFLAG,
  201.                 "ticlabels", TICSLFLAG,
  202.                 "tics", TICS,
  203.                 "ticsabs", TICSABS,
  204.                 "ticsgrid", TICSGRID,
  205.                 "ticsinout", TICSINOUT,
  206.                 "ticsint", TICSINT,
  207.                 "ticslog", TICSLOG,
  208.                 "ticsltop", TICSLTOP,
  209.                 "ticsltype", TICSLTYPE,
  210.                 "ticsop", TICSOP,
  211.                 "ticsprec", TICSPREC,
  212.                 "ticssize", TICSSIZE,
  213.                 "title", TITLE,
  214.                 "view", VIEW,
  215.                 "world", WORLD,
  216.                 "xlabel", XLABEL,
  217.                 "xticang", XTICANG,
  218.                 "xticskip", XTICSKIP,
  219.                 "ylabel", YLABEL,
  220.                 "yticang", YTICANG,
  221.                 "yticskip", YTICSKIP,
  222.                 "zeroflag", ZEROAXIS,
  223.                 "zerotics", ZEROTICS
  224. };
  225.  
  226. int read_param(s)
  227.     char *s;
  228. {
  229.     int didit = 0, gnum, glab, ghid;
  230.     int i, itmp, itmp1, itmp2, type, mtmp, stmp, ltmp, btmp, ls, cs, ps;
  231.     char name[256], title[256], xlabel[256], ylabel[256];
  232.     double dtmp, x1, x2, y1, y2;
  233.     int color, style, active, loctype;
  234.     int xabsflag;
  235.     int yabsflag;
  236.     int xticflag;
  237.     int yticflag;
  238.     int xgridflag;
  239.     int ygridflag;
  240.     int xticsintflag;
  241.     int yticsintflag;
  242.     int xticinoutflag;
  243.     int yticinoutflag;
  244.     int xticlflag;
  245.     int yticlflag;
  246.     int xticslog;
  247.     int yticslog;
  248.     int xticangle;
  249.     int yticangle;
  250.     int xticlskip;
  251.     int yticlskip;
  252.     int xticopflag;
  253.     int yticopflag;
  254.     int xtopflag;
  255.     int ytopflag;
  256.     int ix;
  257.     int iy;
  258.     int fformx;
  259.     int fformy;
  260.     int xzflag;
  261.     int yzflag;
  262.     int xztflag;
  263.     int yztflag;
  264.  
  265.  
  266.     if (s[0] == '@') {
  267.     s++;
  268.     }
  269.     if (s[0] != '#') {
  270.     sscanf(s, "%s", name);
  271.     type = findf(parmnames, name, MAXPAR);
  272.     if (type >= 0) {
  273.         type = parmnames[type].type;
  274.         /* printf("%s %d\n",name,type); */
  275.         switch (type) {
  276.         case BOX0:
  277.         sscanf(s, "%*s %le %le %le %le %d %d %d %d", &x1, &y1, &x2, &y2, &color, &style, &active, &loctype);
  278.         printf("with box\n");
  279.         printf("box on\n");
  280.         printf("box loctype %s\n", loctype ? "VIEW" : "WORLD");
  281.         if (loctype == 0) {
  282.             printf("box g0\n");
  283.         }
  284.         printf("box %lf, %lf, %lf, %lf\n", x1, y1, x2, y2);
  285.         printf("box linestyle %d\n", style);
  286.         printf("box linewidth %d\n", color);
  287.         printf("box def\n");
  288.         break;
  289.         case BOXCOL:
  290.         sscanf(s, "%*s %d", &itmp);
  291.         printf("frame linewidth %d\n", itmp);
  292.         break;
  293.         case BOXLIN:
  294.         sscanf(s, "%*s %d", &itmp);
  295.         printf("frame linestyle %d\n", itmp);
  296.         break;
  297.         case BOXWID:
  298.         sscanf(s, "%*s %d", &itmp);
  299.         printf("frame linewidth %d\n", itmp);
  300.         break;
  301.         case BOXTYPE:
  302.         sscanf(s, "%*s %d %d", &itmp1, &itmp2);
  303.         printf("frame %s\n", itmp1 ? "on" : "off");
  304.         printf("frame type %d\n", !itmp2);
  305.         break;
  306.         case DEFNTICS:
  307.         sscanf(s, "%*s %d %d", &itmp1, &itmp2);
  308.         printf("xaxis tick default %d\n", itmp1);
  309.         printf("yaxis tick default %d\n", itmp2);
  310.         break;
  311.         case DEFSYMSIZE:
  312.         sscanf(s, "%*s %lf", &dtmp);
  313.         for (i = 0; i < 30; i++) {
  314.             printf("s%1d symbol size %lf\n", i, dtmp);
  315.         }
  316.         break;
  317.         case ERRBAR:
  318.         sscanf(s, "%*s %d %d", &stmp, &itmp);
  319. /*
  320.         makeseterrbar(stmp, itmp);
  321. */
  322.         break;
  323.         case ERRBARPER:
  324.         sscanf(s, "%*s %lf", &dtmp);
  325.         break;
  326.         case ERRBARTYPE:
  327.         sscanf(s, "%*s %d %d", &stmp, &itmp);
  328. /*
  329.         seterrbarxy(stmp, itmp);
  330. */
  331.         break;
  332.         case LABDEF:
  333.         sscanf(s, "%*s %d", &itmp);
  334.         break;
  335.         case LEGSTR:
  336.         strcpy(name, s + 10);
  337.         name[strlen(name) - 1] = 0;
  338.         if (strlen(name)) {
  339.             printf("legend string %d \"%s\"\n", curset++, name);
  340.         }
  341.         break;
  342.         case LEGFLAG:
  343.         sscanf(s, "%*s %d", &itmp);
  344.         printf("legend %s\n", itmp ? "ON" : "OFF");
  345.         break;
  346.         case LEGGAP:
  347.         sscanf(s, "%*s %d", &itmp);
  348.         printf("legend vgap %d\n", itmp);
  349.         break;
  350.         case LEGLEN:
  351.         sscanf(s, "%*s %d", &itmp);
  352.         printf("legend length %d\n", itmp);
  353.         break;
  354.         case LEGLOC:
  355.         {
  356.             int ncheck;
  357.  
  358.             ncheck = sscanf(s, "%*s %lf %lf %d", &x1, &y1, &itmp);
  359.             printf("legend %lf, %lf\n", x1, y1);
  360.             if (ncheck == 2) {
  361.             } else {
  362.             printf("legend loctype %s\n", itmp ? "VIEW" : "WORLD");
  363.             }
  364.         }
  365.         break;
  366.         case LINES:
  367.         {
  368.             int ncheck, arrow;
  369.             double asize;
  370.  
  371.             ncheck = sscanf(s, "%*s %le %le %le %le %d %d %d %d %d %le", &x1, &y1, &x2, &y2,
  372.                     &color, &style, &arrow,
  373.                     &active, &loctype, &asize);
  374.             if (ncheck == 9) {
  375.             asize = 1.0;
  376.             }
  377.             printf("with line\n");
  378.             printf("line on\n");
  379.             printf("line loctype %s\n", loctype ? "VIEW" : "WORLD");
  380.             if (loctype == 0) {
  381.             printf("line g0\n");
  382.             }
  383.             printf("line %lf, %lf, %lf, %lf\n", x1, y1, x2, y2);
  384.             printf("line linestyle %d\n", style + 1);
  385.             printf("line linewidth %d\n", color);
  386.             printf("line arrow %d\n", arrow);
  387.             printf("line arrow size %lf\n", asize);
  388.             printf("line def\n");
  389.             break;
  390.         }
  391.         case SETPROPS:
  392.         {
  393.             int ls, ps, cs;
  394.  
  395.             sscanf(s, "%*s %d %d %d %d", &itmp, &ls, &ps, &cs);
  396.             printf("s%1d color %d\n", itmp, cs);
  397.             printf("s%1d linestyle %d\n", itmp, ls);
  398.             printf("s%1d symbol %d\n", itmp, ps);
  399.         }
  400.         break;
  401.         case STRING0:
  402.         if (nstr >= 0) {
  403.             double size, rot;
  404.             int font, just;
  405.  
  406.             sscanf(s, "%*s %lf %lf %lf %d %d %d %d &d",
  407.              &x1, &y1, &size, &rot, &font, &color, &loctype, &just);
  408.             printf("with string\n");
  409.             printf("string on\n");
  410.             printf("string loctype %s\n", loctype ? "VIEW" : "WORLD");
  411.             if (loctype == 0) {
  412.             printf("string g0\n");
  413.             }
  414.             printf("string %lf, %lf\n", x1, y1);
  415.             printf("string color %d\n", color);
  416.         }
  417.         break;
  418.         case STRINGDEF:
  419.         if (nstr >= 0) {
  420.             strcpy(name, s + 10);
  421.             name[strlen(name) - 1] = 0;
  422.             printf("string def \"%s\"\n", name);
  423.         }
  424.         break;
  425.         case SUBTITLE:
  426.         strcpy(title, s + 9);
  427.         title[strlen(title) - 1] = 0;
  428.         printf("subtitle \"%s\"\n", title);
  429.         break;
  430.         case TICS:
  431.         sscanf(s, "%*s %lf %lf %lf %lf", &x1, &x2, &y1, &y2);
  432.         printf("xaxis tick major %lf\n", x1);
  433.         printf("xaxis tick minor %lf\n", x2);
  434.         printf("yaxis tick major %lf\n", y1);
  435.         printf("yaxis tick minor %lf\n", y2);
  436.         break;
  437.         case TICSABS:
  438.         sscanf(s, "%*s %d %d", &xabsflag, &yabsflag);
  439.         printf("xaxis ticklabel sign normal\n");
  440.         printf("yaxis ticklabel sign normal\n");
  441.         break;
  442.         case TICSFLAG:
  443.         sscanf(s, "%*s %d %d", &xticflag, &yticflag);
  444.         printf("xaxis tick %s\n", xticflag ? "on" : "off");
  445.         printf("yaxis tick %s\n", yticflag ? "on" : "off");
  446.         break;
  447.         case TICSGRID:
  448.         sscanf(s, "%*s %d %d", &xgridflag, &ygridflag);
  449.         printf("xaxis tick major grid %s\n", xgridflag ? "on" : "off");
  450.         printf("yaxis tick major grid %s\n", ygridflag ? "on" : "off");
  451.         break;
  452.         case TICSINT:
  453.         sscanf(s, "%*s %d %d", &xticsintflag, &yticsintflag);
  454.         break;
  455.         case TICSINOUT:
  456.         sscanf(s, "%*s %d %d", &xticinoutflag, &yticinoutflag);
  457.         break;
  458.         case TICSLFLAG:
  459.         sscanf(s, "%*s %d %d", &xticlflag, &yticlflag);
  460.         printf("xaxis ticklabel %s\n", xticflag ? "on" : "off");
  461.         printf("yaxis ticklabel %s\n", yticflag ? "on" : "off");
  462.         break;
  463.         case TICSLOG:
  464.         sscanf(s, "%*s %d %d", &xticslog, &yticslog);
  465.         break;
  466.         case XTICANG:
  467.         sscanf(s, "%*s %d", &xticangle);
  468.         break;
  469.         case YTICANG:
  470.         sscanf(s, "%*s %d", &yticangle);
  471.         break;
  472.         case XTICSKIP:
  473.         sscanf(s, "%*s %d", &xticlskip);
  474.         break;
  475.         case YTICSKIP:
  476.         sscanf(s, "%*s %d", &yticlskip);
  477.         break;
  478.         case TICSOP:
  479.         sscanf(s, "%*s %d %d", &xticopflag, &yticopflag);
  480.         break;
  481.         case TICSLTOP:
  482.         sscanf(s, "%*s %d %d", &xtopflag, &ytopflag);
  483.         sscanf(s, "%*s %d %d", &ix, &iy);
  484.         break;
  485.         case TICSLTYPE:
  486.         sscanf(s, "%*s %d %d", &fformx, &fformy);
  487.         sscanf(s, "%*s %d %d", &ix, &iy);
  488.         break;
  489.         case TICSPREC:
  490.         sscanf(s, "%*s %d %d", &ix, &iy);
  491.         printf("xaxis ticklabel prec %d\n", ix);
  492.         printf("yaxis ticklabel prec %d\n", iy);
  493.         break;
  494.         case TICSSIZE:
  495.         sscanf(s, "%*s %lf %lf", &x1, &y1);
  496.         printf("xaxis tick size %lf\n", x1);
  497.         printf("yaxis tick size %lf\n", x1);
  498.         break;
  499.         case TITLE:
  500.         strcpy(title, s + 6);
  501.         title[strlen(title) - 1] = 0;
  502.         printf("title \"%s\"\n", title);
  503.         break;
  504.         case VIEW:
  505.         sscanf(s, "%*s %lf %lf %lf %lf", &x1, &x2, &y1, &y2);
  506.         printf("view xmin %lf\n", x1);
  507.         printf("view xmax %lf\n", x2);
  508.         printf("view ymin %lf\n", y1);
  509.         printf("view ymax %lf\n", y2);
  510.         break;
  511.         case WORLD:
  512.         sscanf(s, "%*s %lf %lf %lf %lf", &x1, &x2, &y1, &y2);
  513.         printf("world xmin %lf\n", x1);
  514.         printf("world xmax %lf\n", x2);
  515.         printf("world ymin %lf\n", y1);
  516.         printf("world ymax %lf\n", y2);
  517.         break;
  518.         case XLABEL:
  519.         strcpy(xlabel, s + 7);
  520.         xlabel[strlen(xlabel) - 1] = 0;
  521.         printf("xaxis label \"%s\"\n", xlabel);
  522.         break;
  523.         case YLABEL:
  524.         strcpy(ylabel, s + 7);
  525.         ylabel[strlen(ylabel) - 1] = 0;
  526.         printf("yaxis label \"%s\"\n", ylabel);
  527.         break;
  528.         case ZEROAXIS:
  529.         sscanf(s, "%*s %d %d", &xzflag, &yzflag);
  530.         printf("zeroxaxis bar %s\n", xzflag ? "on" : "off");
  531.         printf("zeroyaxis bar %s\n", yzflag ? "on" : "off");
  532.         break;
  533.         case ZEROTICS:
  534.         sscanf(s, "%*s %d %d", &xztflag, &yztflag);
  535.         printf("zeroxaxis tick %s\n", xztflag ? "on" : "off");
  536.         printf("zeroyaxis tick %s\n", yztflag ? "on" : "off");
  537.         break;
  538.         }            /* end switch */
  539.         return (type);    /* type found */
  540.     }            /* end if */
  541.     }                /* end if */
  542. }
  543.